﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text;
using Utils;
using System.Data;

public partial class account_Login : FBasePage
{

    // Methods
    protected void btnLogin_Click(object sender, EventArgs e)
    {
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (base.Request.HttpMethod == "POST")
        {
            string str = "";
            string str2 = "";
            if ((base.Request.Form["username"] != null) && (base.Request.Form["password"] != null))
            {
                str = Helper.GetString(base.Request.Form["username"].ToString().Trim(), string.Empty);
                str2 = base.Request.Form["password"].ToString().Trim();
            }
            if (str == "")
            {
                this.SetError("请输入用户名或者用户邮箱！");
                base.Response.Redirect("Login.aspx");
            }
            if (str2 == "")
            {
                this.SetError("请输入用户密码！");
                base.Response.Redirect("Login.aspx");
            }
            string strWhere = "";
            strWhere = string.Format(" username='{0}' or Email='{1}'", str, str);
            Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
            DataSet list = info.GetList(strWhere);
            if ((list != null) && (list.Tables.Count > 0))
            {
                if (list.Tables[0].Rows.Count > 0)
                {
                    string userName = list.Tables[0].Rows[0]["Username"].ToString();
                    string str5 = list.Tables[0].Rows[0]["Password"].ToString();
                    string s = list.Tables[0].Rows[0]["id"].ToString();
                    string str7 = list.Tables[0].Rows[0]["Manager"].ToString();
                    string str8 = list.Tables[0].Rows[0]["Enable"].ToString();
                    string str9 = list.Tables[0].Rows[0]["Email"].ToString();
                    if (str5 == FormsAuthentication.HashPasswordForStoringInConfigFile(str2 + "@4!@#$%@", "md5"))
                    {
                        if (((base.ASSystem != null) && (base.ASSystem.Emailverify == 1)) && (str8 == "N"))
                        {
                            this.Session["useremail"] = str9;
                            base.Response.Redirect("verify.aspx");
                        }
                        else
                        {
                            FormsAuthentication.SetAuthCookie(userName, false);
                            string userHostAddress = base.Request.UserHostAddress;
                            info.UpdateLoginInfo(int.Parse(s), userHostAddress, DateTime.Now.ToString());
                            if (str7.ToUpper() == "Y")
                            {
                                base.SetCookie("admin", s);
                            }
                            string refer = base.GetRefer();
                            base.Response.Redirect(refer);
                        }
                    }
                    else
                    {
                        this.SetError("你输入的密码错误！");
                        base.Response.Redirect("Login.aspx");
                    }
                }
                else
                {
                    this.SetError("该用户不存在！");
                    base.Response.Redirect("Login.aspx");
                }
            }
        }
    }

}